package com.rashith.metro.alfa;

import com.rashith.metro.alfa.sam.ShowListActivity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class PopUpActivity  extends Activity{
	
	private String id,name;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
		
		
		setContentView(R.layout.popup);
		
		Intent caller = getIntent();
		name = caller.getExtras().getString("name");
		id = caller.getExtras().getString("ID");
		final String tel = caller.getExtras().getString("tel");
		
		TextView nameTV = (TextView) findViewById(R.id.textView1);
		nameTV.setText(name);
		
		TextView telTV = (TextView) findViewById(R.id.textView2);
		telTV.setText(tel);
		
		
		
		
		ImageButton call = (ImageButton) findViewById(R.id.call);
		call.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String s = "tel:" + tel;
				startActivityForResult(new Intent(Intent.ACTION_DIAL,
						Uri.parse(s)), 1);
			}
		});
		Button bt = (Button) findViewById(R.id.buttonMoreInfo);
		bt.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent i = new Intent(PopUpActivity.this, ShowListActivity.class) ;
				i.putExtra("ID", id);
				i.putExtra("NAME", name);
				startActivity(i);
				
			}
		});
		
		ImageButton map =(ImageButton) findViewById(R.id.map);
		map.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// this is hard coded
				String map_string = "geo:6.914836,79.971955?z=16";
				startActivity(new Intent(
						android.content.Intent.ACTION_VIEW,
						Uri.parse(map_string)));
			}
		});
		
		
		
		try{
			String icon_name = "i" + id;
			int x = getResources().getIdentifier(icon_name, "drawable",
					getPackageName());
			
			if( x != 0){
				ImageView iv = (ImageView) findViewById(R.id.imageView1);
				iv.setImageResource(x);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
